home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000097_icon-group-sender _Fri Apr 9 13:03:04 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id NAA23393
for icon-group-addresses; Fri, 9 Apr 1999 13:01:54 -0700 (MST)
Message-Id: <199904092001.NAA23393@baskerville.CS.Arizona.EDU>
From: "Nevin Liber" <nevin@eviloverlord.com>
To: <icon-group@optima.CS.Arizona.EDU>
Cc: "Hudon, Christian (EXCHANGE:MTL:6X16)" <chudon@americasm01.nt.com>
Subject: RE: Deep copy in Icon?
Date: Fri, 9 Apr 1999 10:33:54 -0500
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
> procedure deepcopy(x, t)
> /t := table()
> case type(x) of {
> "list"|"table"|"set"|"record" : {
> e := t[image(x)]
> if /e then {
> e := copy(x)
> t[image(x)] := e
> every sub := !e do sub := deepcopy(sub, t)
> }
> return e
> }
> default: return x
> }
> end
> (This is supposed to do a deep copy of an arbitrary object, preserving
> the structure.)
First off, good job on dealing with the problems of self-referential data
structures, such as
L := list()
put(L, L)
although you can just use x instead of image(x) in your above snippet and it
will still work.
> I thought you could assign to the elements of a set, list, etc. with
> something like
> every e := !l do e := foo(e)
What you need is something like:
every i := 1 to *l do l[i] := foo(l[i])
To borrow from C++ terminology, the difference is that l[i] is a "reference"
(l-value) to element i in list l, while e is the "value" of element i in
list l.
__
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (312) 855-1000 x199